package me.jessyan.mvparms.demo.mvp.ui.adapter;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jess.arms.base.BaseHolder;
import com.jess.arms.base.DefaultAdapter;
import com.platform.ai.control.R;


import java.util.List;

import butterknife.BindView;

import me.jessyan.mvparms.demo.mvp.model.entity.Device;
import me.jessyan.mvparms.demo.mvp.ui.holder.ItemClickListener;

/**
 * Created by 95 on 2017/9/5.
 */
public class LightMainAdapter extends DefaultAdapter<Device> {
    ItemClickListener itemClickListener;
    int type = 0;
    public LightMainAdapter(List<Device> discovers, ItemClickListener itemClickListener) {
        super(discovers);
        this.type = 0;
        this.itemClickListener = itemClickListener;
    }

    public LightMainAdapter(List<Device> discovers,ItemClickListener itemClickListener,int type) {
        super(discovers);
        this.type = type;
        this.itemClickListener = itemClickListener;
    }

    @Override
    public BaseHolder getHolder(View v, int viewType) {
        return new DeviceHolder(v,itemClickListener);
    }

    @Override
    public int getLayoutId(int viewType) {
        if(type == 0 ){
            return R.layout.item_light;
        }else{
            return R.layout.item_tag;
        }

    }

    public class DeviceHolder extends BaseHolder<Device> {
        @BindView(R.id.iv_device)
        ImageView mImg;

        @BindView(R.id.tv_device)
        TextView mLabel;

        @BindView(R.id.ll_item)
        View mItem;


        ItemClickListener itemClickListener;
        public DeviceHolder(View itemView,ItemClickListener itemClickListener) {
            super(itemView);
            this.itemClickListener = itemClickListener;
        }

        @Override
        public void setData(Device data, int position) {
            mImg.setImageResource(data.getIcon());
            mLabel.setText(data.getName());
            if(data.getState() == 0){
                mLabel.setTextColor(Color.parseColor("#333333"));
            }else{
                mLabel.setTextColor(Color.parseColor("#EE685E"));
            }
            mItem.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    itemClickListener.onItemClick(position,data);
                }
            });
        }
    }



}
